#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define lc (o<<1)
#define rc (o<<1|1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=5e3+10;
int n,head[MAXN*5],cnt;
struct edge
{
	int v,next,flow,cost;
}e[MAXN*40];
void addedge(int x,int y,int f,int c)
{
	e[cnt]=(edge){y,head[x],f,c};
	head[x]=cnt++;
	swap(x,y);
	e[cnt]=(edge){y,head[x],0,-c};
	head[x]=cnt++;
	return;
}
struct MCMF
{
	int S,T,dis[MAXN*5],flow,cost;
	bool vis[MAXN*5];
	int aug(int u,int _min)
	{
		vis[u]=true;
		if(u==T)
		{
			flow+=_min;
			cost+=dis[S]*_min;
			return _min;
		}
		int ret=0,k;
		for(int i=head[u];~i;i=e[i].next)
		{
			int v=e[i].v;
			if(vis[v]||!e[i].flow||dis[v]-dis[u]+e[i].cost)continue;
			k=aug(v,min(_min-ret,e[i].flow));
			e[i].flow-=k;
			e[i^1].flow+=k;
			ret+=k;
			if(ret==_min)break;
		}
		return ret;
	}
	bool mdf()
	{
		int _min=INF;
		for(int u=S;u<=T;++u)
		{
			if(!vis[u])continue;
			for(int i=head[u];~i;i=e[i].next)
			{
				int v=e[i].v;
				if(vis[v]||!e[i].flow)continue;
				_min=min(_min,dis[v]-dis[u]+e[i].cost);
			}
		}
		if(_min==INF)return false;
		for(int i=S;i<=T;++i)
			if(vis[i])
				dis[i]+=_min;
		return true;
	}
	void zkw()
	{
		do do memset(vis,0,sizeof(vis));
		while(aug(S,INF));
		while(mdf());
		return;
	}
}T2;
struct Seg_T
{
	void build(int o,int l,int r)
	{
		if(l==r)
		{
			addedge(o+n,T2.T,1,0);
			return;
		}
		build(lc,l,mid);
		addedge(o+n,lc+n,INF,0);
		build(rc,mid+1,r);
		addedge(o+n,rc+n,INF,0);
		return;
	}
	void update(int o,int l,int r,int yl,int yr,int x,int k)
	{
		if(yl<=l&&r<=yr)
		{
			addedge(x,o+n,INF,10000-k);
			return;
		}
		if(yl<=mid)update(lc,l,mid,yl,yr,x,k);
		if(yr>mid)update(rc,mid+1,r,yl,yr,x,k);
		return;
	}
}T1;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();
	memset(head,-1,sizeof(head));
	T2.T=n*5+1;
	T1.build(1,1,n);
	for(int i=1;i<=n;++i)
	{
		int a=read(),b=read()-1,c=read();
		addedge(T2.S,i,1,0);
		T1.update(1,1,n,a,b,i,c);
	}
	T2.zkw();
	printf("%d\n",T2.flow*10000-T2.cost);
	return 0;
}
